<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 1. 普通函数中是有this标识符
    function foo() {
      console.log("foo:", this)
    }
    foo()
    foo.apply("aaa")

    // 2. 箭头函数中,没有this
    var bar = () => {
      console.log("bar:", this)
    }
    bar()
    console.log("全局this:", this)
    bar.apply("bbb")

    // 3.1 this的查找规则1
    var obj = {
      name: 'obj',
      foo: function () {
        var bar = () => {
          console.log("bar:", this)
        }
        return bar
      }
    }
    var fn = obj.foo()
    fn.apply("ccc")

    // 3.2 this的查找规则2
    var obj = {
      name: 'obj',
      foo: () => {
        var bar = () => {
          console.log("bar1:", this)
        }
        return bar
      }
    }

    var fn = obj.foo()
    fn.apply("ddd")
  </script>
</body>

</html>